<template>
  <div class="content">
    <div class="tableBox posting_box_list">
      <el-table
        :data="tableData"
        stripe
        style="width: 100%"
        v-loading="loading"
        border
      >
        <template v-for="(item,index) in allData">
          <el-table-column
            :key="index"
            :prop="item.value"
            v-if="item.value!=='opt' && item.value!='positionname' && item.value!='releasetime'"
            :label="item.label"
            align="center"
          ></el-table-column>
          <el-table-column
            :key="item.value"
            v-if="item.value=='positionname'"
            :prop="item.value"
            :label="item.label"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                @click="showDetail(scope.row)"
                type="text"
                size="small"
              >{{scope.row.positionname}}</el-button>
            </template>
          </el-table-column>
          <el-table-column
            :key="item.value"
            v-if="item.value=='releasetime'"
            :prop="item.value"
            :label="item.label"
            width="140px"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{scope.row.releasetime}}</span>
            </template>
          </el-table-column>
          <el-table-column
            :key="item.value"
            v-else-if="item.value=='opt'"
            label="操作"
            width="220px"
            align="center"
          >
            <template slot-scope="scope">
              <el-button
                @click="lookLog(scope.row)"
                type="text"
                size="small"
              >查看日志</el-button>
              <el-button
                @click="remove(scope.row)"
                type="text"
                v-show="global.powerAllBtn.qygl.gwglxjBtn"
              >下架</el-button>
              <!-- <el-button @click="open6" type="text">驳回</el-button> -->
              <!-- <el-button v-show="scope.row.remark === '1'" type="text" size="small" @click="remove(scope.row)">下架</el-button> -->
              <el-button
                type="text"
                size="small"
                @click="toReport(scope.row,4)"
                v-show="global.powerAllBtn.qygl.gwglsbBtn"
              >上报</el-button>
            </template>
          </el-table-column>
        </template>
      </el-table>
    </div>
    <div style="padding:20px 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="ScheduleCurrentChange"
        :current-page="pages.pagenum"
        :page-sizes="[10,20, 30, 50,100]"
        :page-size="pages.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pages.total"
        background
      ></el-pagination>
    </div>
    <el-dialog
      :visible.sync="detailFlag"
      width="800px"
      center
    >
      <position-info
        v-if="detailFlag"
        :id="positionid"
        :type="postType"
        :currentAction="Action"
        v-on:cancle="cancle"
        :company="company"
      ></position-info>
      <div slot="footer">
        <!-- <el-button>取 消</el-button>
        <el-button type="primary">确 定</el-button>-->
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="warnDialogVisible"
      width="500px"
      @close="closeWarnDialog"
    >
      <div class="warn-dialog-header">
        <span>上报原因</span>
      </div>
      <div class="warn-dialog-body">
        <div class="warn-dialog-body-title">发送内容</div>
        <el-input
          type="textarea"
          :rows="6"
          v-model.trim="reportContent"
        ></el-input>
        <div class="warn-dialog-btn">
          <el-button
            style="margin-right: 30px;"
            @click="warnDialogVisible = false"
          >取消</el-button>
          <el-button
            type="primary"
            @click="confirmReport"
          >确定</el-button>
        </div>
      </div>
    </el-dialog>
    <el-dialog
      :visible.sync="showLog"
      width="1024px"
      custom-class="showlog"
    >
      <showLog :reportid="reportId"></showLog>
    </el-dialog>

    <el-dialog
      :visible.sync="confirmDialogVisible"
      width="420px"
      custom-class="confirm"
      title="提示"
    >
      <span>下架将返还{{restoration.restoremoney}}元,{{restoration.integral}}积分,是否继续?</span>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="ignore">移除</el-button>
        <el-button
          type="primary"
          @click="sendRemove"
        >下架</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import showLog from "../showLog.vue";
import positionInfo from "../../socical/post/positionInfo.vue";
export default {
  data () {
    return {
      current: "0",
      companyType: '',
      tableData: [],
      loading: false,
      allData: [],
      currentType: '',
      pages: {
        pagesize: 10,
        total: 0,
        pagenum: 0,
      },
      restoration: {
        positionid: "",
        restoremoney: "",
        restoreintegral: "",
        integral: ''
      },
      detailFlag: false,
      warnDialogVisible: false,

      reportContent: '',
      reportId: '',
      showLog: false,
      positionid: '',
      postType: 0,
      Action: 3,
      confirmDialogVisible: false
    }
  },
  props: ['type'],
  components: {
    showLog,
    positionInfo
  },
  created () {
    this.allData = [{ label: "招聘企业", value: "companyname" },
    { label: "职位名称", value: "positionname" },
    { label: "工作地点", value: "address" },
    { label: "薪资待遇", value: "offer" },
    { label: "要求年限", value: "worklife" },
    { label: "招聘人数", value: "recruitment" },
    { label: "发布日期", value: "releasetime" },
    { label: "操作", value: "opt" }
    ]
    this.global = this.GLOBAL;
    this.getData();
  },
  methods: {
    //获取列表
    getData () {
      if (!this.type) {
        return;
      }
      this.currentType = this.type;
      this.loading = true;
      let obj = {
        pagenum: this.pages.pagesize,
      }
      this.$axios.post('/app/v1/platform/unusual/todoList', {
        "type": this.type,
        pagesize: this.pages.pagesize,
        pagenum: this.pages.pagenum
      }).then(resp => {
        if (resp.data.message === 'success.') {

          let temp = resp.data.data.list;
          temp.forEach(el => {
            if (!el.miniwage && el.maxwage) {
              el.offer = `${parseInt(el.maxwage) / 1000}K以下`;
            } else if (!el.maxwage && el.miniwage) {
              el.offer = `${parseInt(el.miniwage) / 1000}K以上`;
            } else if (el.maxwage == el.miniwage) {
              el.offer = `${parseInt(el.miniwage) / 1}元/小时`
            } else {
              el.offer = `${parseInt(el.miniwage) / 1000}-${parseInt(
                el.maxwage
              ) / 1000}K`;
            }
          });
          this.tableData = temp || [];
          this.pages.total = Number(resp.data.data.totalnum);
          this.pages.pagesize = Number(resp.data.data.pagesize);
          this.loading = false;

        }
      })
    },

    showDetail (row) {
      this.positionid = row.id;
      this.remark = '';
      this.company = row.companyname;
      this.detailFlag = true;
    },



    // 2.下架
    remove (row) {

      let pid = row.id;
      this.reportId = row.reportid;
      this.$axios
        .post("/app/v1/platform/company/cancelrefund", { positionid: pid })
        .then(res => {
          if (res.data.message === "success.") {
            this.confirmDialogVisible = true;
            this.restoration.positionid = pid;
            (this.restoration.restoremoney = Math.floor(
              res.data.data.restoremoney * 100 / 100
            )),
              (this.restoration.restoreintegral = Math.floor(
                res.data.data.restoreintegral * 100 / 100
              ));
            this.restoration.integral = res.data.data.restoreintegral;

          } else if (res.data.code == '198') {
            this.$confirm(
              `该岗位已下架`,
              "提示",
              {
                distinguishCancelAndClose: true,
                confirmButtonText: "确定",
                showCancelButton: false
              }
            )
              .then(() => {
                let currentData = {
                  reportid: this.reportId,
                  status: 2,
                  content: "已被hr下架"
                }
                this.reportCall(currentData)
              })
              .catch(action => {
              });
          }
          else {
            this.$message({
              message: res.data.message,
              type: "error"
            });
          }
        });
    },


    // 3.确定下架
    sendRemove () {

      this.$axios
        .post("/app/v1/platform/company/cancelposition", this.restoration)
        .then(res => {
          if (res.data.message === "success.") {
            this.$message({
              message: "下架成功!",
              type: "success"
            });
            // var currentData = {
            //   reportid: this.restoration.positionid,
            //   status: 1,
            //   content: currentData.content || ''
            // }
            // this.$emit('reportCallback', currentData)
          } else {
            this.$message({
              message: res.data.message,
              type: "error"
            });
          }
          this.confirmDialogVisible = false;
          this.getData();

        });
    },
    //上报
    toReport (r, type) {
      this.warnDialogVisible = true;
      this.reportType = type;
      this.reportContent = '';
      this.reportId = r.reportid;
    },
    close () {
      this.checkFlag = false;
      this.getData(this.companyType);
    },
    closeWarnDialog () {
      this.reportContent = "";
    },
    handleSizeChange (val) {
      this.pages.pagenum = 1;
      this.pages.pagesize = val;
      this.getData();
    },
    //分页查询
    ScheduleCurrentChange (val) {
      this.pages.pagenum = val;
      this.getData();
    },
    //上报里确定
    confirmReport () {
      if (!this.reportContent) {
        this.$message({
          type: "warning",
          message: "上报内容不能为空!"
        });
        return;
      }
      let currentData = {
        reportid: this.reportId,
        status: 0,
        content: this.reportContent || ''
      }
      this.reportCall(currentData)
    },

    ignore () {
      let currentData = {
        reportid: this.reportId,
        status: 2,
        content: "不处理"
      }
      this.reportCall(currentData)
    },

    // rebut (row) {
    //   this.reportId = row.reportid;
    //   this.$confirm(
    //     `确定驳回这条数据吗?`,
    //     "提示",
    //     {
    //       confirmButtonText: "确定",
    //       cancelButtonText: "取消",
    //       type: "warning"
    //     }
    //   )
    //     .then(() => {

    //       let currentData = {
    //         reportid: this.reportId,
    //         status: 2,
    //         content: "不处理"
    //       }
    //       this.reportCall(currentData)
    //     })
    //     .catch(() => {
    //       this.$message({
    //         type: "info",
    //         message: "已取消"
    //       });
    //     });

    // },
    //待办提交
    reportCall (data) {
      this.$axios.post('app/v1/platform/unusual/todoHandleSubmit',
        data
      ).then(resp => {
        if (resp.data.message === 'success.') {

          // this.tableData = resp.data.data;
          // this.pages.total = resp.data.data.length;
          this.loading = false;

        } else {
          this.$message({
            message: resp.data.message,
            type: "error"
          });
        }
        this.warnDialogVisible = false;
        this.confirmDialogVisible = false;
        this.getData();
      })

    },
    // reportCallback (currentData) {
    //   var data = {
    //     reportid: currentData.reportid,
    //     status: currentData.status,
    //     content: currentData.content || ''
    //   }
    //   this.$emit('reportCallback', data)
    // },
    lookLog (row) {
      this.reportId = row.reportid;
      this.showLog = true;
    },
    cancle (f) {
      this.detailFlag = f;
      this.pages.pagenum = 1;
      this.getData();
    },
  },

}
</script>
<style>
</style>


